<?php
require_once (ROOTDIR."common/db_utils.php");
require_once (ROOTDIR."config/sys_config.php");

//cache head start
if( !isset($cache_time) ) {
    $cache_time=10;
}

$file="cache/cache_".$_SERVER["REQUEST_URI"].".html";
$sid = SysConfig::$OJ_NAME.$_SERVER["HTTP_HOST"];

$OJ_CACHE_SHARE=(isset($OJ_CACHE_SHARE)&&$OJ_CACHE_SHARE)&&!isset($_SESSION['administrator']);

if ( !$OJ_CACHE_SHARE && isset($_SESSION['user_id']) ) {
    $ip = ($_SERVER['REMOTE_ADDR']);
    if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
        $REMOTE_ADDR = $_SERVER['HTTP_X_FORWARDED_FOR'];
        $tmp_ip=explode(',',$REMOTE_ADDR);
        $ip =(htmlentities($tmp_ip[0],ENT_QUOTES,"UTF-8"));
    }
    $sid.=session_id().$ip;
}

if ( isset($_SERVER["REQUEST_URI"]) ) {
    $sid.=$_SERVER["REQUEST_URI"];
}

$sid=md5($sid);
$file = "cache/cache_$sid.html";
$last =0;
if ( file_exists ($file) ) {
    $last = filemtime ( $file );
}

$use_cache=(time () - $last < $cache_time);
if ($use_cache) {
    include ($file);
    exit ();
}
else {
    ob_start ();
}
?>
